package com.orange.proxyPattens.dynamicProxy.interceptor;

import com.orange.proxyPattens.dynamicProxy.UserService;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Description: jdk中的拦截器
 */
public class Log2Interceptor implements InvocationHandler {
    //我们需要在这里创建一个目标对象
    private UserService userService;

    //拦截器初始化
    public Log2Interceptor(UserService userService){
        this.userService=userService;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("日志拦截");
        return method.invoke(userService,args);
    }
}
